
package com.contractmodule.dao;
import com.contractmodule.bean.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import util.*;
public class TbDispatchListProjectBackSectionMiddleDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbDispatchListProjectBackSectionMiddle tbDispatchListProjectBackSectionMiddle=null;
    private List<TbDispatchListProjectBackSectionMiddle> tbDispatchListProjectBackSectionMiddleList=null;

    public boolean add(TbDispatchListProjectBackSectionMiddle inTbDispatchListProjectBackSectionMiddle){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_DispatchListProjectBackSectionMiddle(DispatchListCode,ProjectStateId,UserId) values(?,?,?)";
        pt = conn.prepareStatement(sql);
        
        pt.setString(1,inTbDispatchListProjectBackSectionMiddle.getDispatchListCode());
        pt.setInt(2,inTbDispatchListProjectBackSectionMiddle.getProjectStateId());
        pt.setInt(3,inTbDispatchListProjectBackSectionMiddle.getUserId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inDispatchListProjectBackSectionMiddle){
        return UtilDAO.del("Tb_DispatchListProjectBackSectionMiddle", "DispatchListProjectBackSectionMiddle", inDispatchListProjectBackSectionMiddle);
    }
    public boolean edit(TbDispatchListProjectBackSectionMiddle inTbDispatchListProjectBackSectionMiddle){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_DispatchListProjectBackSectionMiddle set DispatchListCode=?,ProjectStateId=?,UserId=? where DispatchListProjectBackSectionMiddle=?";
        pt = conn.prepareStatement(sql);
        pt.setString(1,inTbDispatchListProjectBackSectionMiddle.getDispatchListCode());
        pt.setInt(2,inTbDispatchListProjectBackSectionMiddle.getProjectStateId());
        pt.setInt(3,inTbDispatchListProjectBackSectionMiddle.getUserId());
        pt.setInt(4,inTbDispatchListProjectBackSectionMiddle.getDispatchListProjectBackSectionMiddle());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbDispatchListProjectBackSectionMiddle getTbDispatchListProjectBackSectionMiddleByDispatchListProjectBackSectionMiddle(int inDispatchListProjectBackSectionMiddle) {
        tbDispatchListProjectBackSectionMiddle=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_DispatchListProjectBackSectionMiddle where DispatchListProjectBackSectionMiddle=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inDispatchListProjectBackSectionMiddle);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbDispatchListProjectBackSectionMiddle == null)tbDispatchListProjectBackSectionMiddle = getTbDispatchListProjectBackSectionMiddle(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbDispatchListProjectBackSectionMiddle;
    }
    public List<TbDispatchListProjectBackSectionMiddle> getTbDispatchListProjectBackSectionMiddleAll() {
        tbDispatchListProjectBackSectionMiddleList=new ArrayList<TbDispatchListProjectBackSectionMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_DispatchListProjectBackSectionMiddle";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbDispatchListProjectBackSectionMiddleList.add(getTbDispatchListProjectBackSectionMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbDispatchListProjectBackSectionMiddleList;
    }
    public List<TbDispatchListProjectBackSectionMiddle> getTbDispatchListProjectBackSectionMiddleAll(VskPage vp) {
        tbDispatchListProjectBackSectionMiddleList=new ArrayList<TbDispatchListProjectBackSectionMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_DispatchListProjectBackSectionMiddle";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_DispatchListProjectBackSectionMiddle", "DispatchListProjectBackSectionMiddle"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbDispatchListProjectBackSectionMiddleList.add(getTbDispatchListProjectBackSectionMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbDispatchListProjectBackSectionMiddleList;
    }
    /**
     * get the all backSectionId by dispatchCode
     *@author qingyu zhang
     *@function:
     * @param dispatchCode
     * @return
     *2011-6-19
     *上午10:34:56
     *ProjectManagerT
     *com.contractmodule.dao
     *String
     */
    
    public String getBackSectionId(String dispatchCode){
    	String lastBackSectionId="";
    	List<TbDispatchListProjectBackSectionMiddle> mid = this.getTbDispatchListProjectBackSectionMiddleByDispatchCode(dispatchCode);
    	if(mid!=null&&mid.size()>0){
    		for(TbDispatchListProjectBackSectionMiddle mi:mid){
    			if(lastBackSectionId.equals("")){
    				lastBackSectionId+=mi.getBackSectionId();
    			}else{
    				lastBackSectionId+=","+mi.getBackSectionId();
    			}
    		}
    	}
    	return lastBackSectionId;
    }
    
    public String getProjectStateId(String dispatchCode){
    	String lastProjectStateId="";
    	List<TbDispatchListProjectBackSectionMiddle> mid = this.getTbDispatchListProjectBackSectionMiddleByDispatchCode(dispatchCode);
    	if(mid!=null&&mid.size()>0){
    		for(TbDispatchListProjectBackSectionMiddle mi:mid){
    			if(lastProjectStateId.equals("")){
    				lastProjectStateId+=mi.getProjectStateId();
    			}else{
    				lastProjectStateId+=","+mi.getProjectStateId();
    			}
    		}
    	}
    	return lastProjectStateId;
    }
    
    /**
     * get the dispatchProjectBaction by the dispatchCode
     *@author qingyu zhang
     *@function:
     * @param dispatchCode
     * @return
     *2011-6-19
     *上午10:26:29
     *ProjectManagerT
     *com.contractmodule.dao
     *TbDispatchListProjectBackSectionMiddle
     */
    public  List<TbDispatchListProjectBackSectionMiddle>  getTbDispatchListProjectBackSectionMiddleByDispatchCode(String dispatchCode) {
    	  tbDispatchListProjectBackSectionMiddleList=new ArrayList<TbDispatchListProjectBackSectionMiddle>();
          try{
              conn = ConnectDB.getSqlServerConnection();
              sql = "select * from Tb_DispatchListProjectBackSectionMiddle where DispatchListCode='"+dispatchCode+"'";
              pt = conn.prepareStatement(sql);
              rs = pt.executeQuery();
              while (rs.next()) {
                  tbDispatchListProjectBackSectionMiddleList.add(getTbDispatchListProjectBackSectionMiddle(rs));
              }
          }catch(Exception e){
              e.printStackTrace();
          }finally {
                          ConnectDB.closeSqlConnection();        }
          return tbDispatchListProjectBackSectionMiddleList;
    }
    public TbDispatchListProjectBackSectionMiddle getTbDispatchListProjectBackSectionMiddle(ResultSet rs) throws Exception{
        TbDispatchListProjectBackSectionMiddle tbDispatchListProjectBackSectionMiddle = new TbDispatchListProjectBackSectionMiddle();
        tbDispatchListProjectBackSectionMiddle.setDispatchListProjectBackSectionMiddle(rs.getInt("DispatchListProjectBackSectionMiddle"));
        tbDispatchListProjectBackSectionMiddle.setDispatchListCode(rs.getString("DispatchListCode"));
        tbDispatchListProjectBackSectionMiddle.setBackSectionId(rs.getInt("BackSectionId"));
        tbDispatchListProjectBackSectionMiddle.setProjectStateId(rs.getInt("ProjectStateId"));
        tbDispatchListProjectBackSectionMiddle.setUserId(rs.getInt("UserId"));
        tbDispatchListProjectBackSectionMiddle.setCreateTime(rs.getString("CreateTime"));
        return tbDispatchListProjectBackSectionMiddle;
    }
}
